package com.qf.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    /***
     * 声明交换机
     */
    @Bean(name = "itemDirectExchange")
    public Exchange directExchange(){
        return ExchangeBuilder.topicExchange("exchange_direct_demo01").durable(true).build();//设置交换机，声明类型，设置持久化
    }

    @Bean(name = "itemQueue01")
    public Queue itemQueue(){
        return QueueBuilder.durable("queue_demo01").build();//设置队列，指定名称，设置持久化
    }

    /***
     * 队列绑定到交换机上
     */
    @Bean
    public Binding itemQueueExchange(@Qualifier("itemQueue01") Queue queue,@Qualifier("itemDirectExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("item.insert").noargs();
    }



}
